package com.csxy.hql.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csxy.hql.api.VodClient;
import com.csxy.hql.entity.EduVideo;
import com.csxy.hql.mapper.EduVideoMapper;
import com.csxy.hql.service.EduVideoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    private VodClient vodClient;
    @Override
    public void removeVideoByCourseId(String id) {

        //根据课程id删除课程里面所有视频
        QueryWrapper<EduVideo> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id",id);
        wrapper.select("video_source_id");
        List<EduVideo> eduVideos = baseMapper.selectList(wrapper);
        List<String> list = new ArrayList<>();
        for (EduVideo eduVideo : eduVideos) {
            String videoSourceId = eduVideo.getVideoSourceId();
            if(StringUtils.isNotEmpty(videoSourceId)){
                list.add(videoSourceId);
            }
        }

        //根据多个视频id删除多个视频
        QueryWrapper<EduVideo> queryWapper2 = new QueryWrapper<>();
        queryWapper2.eq("id",list);
        baseMapper.delete(queryWapper2);


    }
}
